﻿using Microsoft.AspNetCore.Mvc;
using MinimalistFoodStreet.BackEnd.Infrastructure.Attributes;
using MinimalistFoodStreet.BackEnd.Infrastructure.Dtos.Request;
using MinimalistFoodStreet.BackEnd.Infrastructure.Dtos.Response;
using MinimalistFoodStreet.BackEnd.Server.IServer;
using MinimalistFoodStreet.BackEnd.Server.Server.ResponseExtend.Tables;

namespace MinimalistFoodStreet.BackEnd.Api.Api.Controllers
{
    /// <summary>
    /// 登录
    /// </summary>
    public class LoginController:BaseController
    {
        private readonly ILoginServer _loginServer;
        /// <summary>
        /// 构造方法
        /// </summary>
        /// <param name="loginServer"></param>
        public LoginController(ILoginServer loginServer) {
            _loginServer=loginServer;
        }
        /// <summary>
        /// 管理员通过账号登录
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> AdministratorLoginByAccount(RequestLoginDto dto)
        {
            return Send(await _loginServer.LoginByAccount(dto, "administrators"));
        }
        /// <summary>
        /// 管理员通过手机号登录
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> AdministratorLoginByPhone(RequestLoginDto dto)
        {
            return Send(await _loginServer.LoginByPhone(dto, "administrators"));
        }
        /// <summary>
        /// 供应商通过账号登录
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> SupplierLoginByAccount(RequestLoginDto dto)
        {
            return Send(await _loginServer.LoginByAccount(dto, "suppliers"));
        }
        /// <summary>
        /// 供应商通过手机号登录
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> SupplierLoginByPhone(RequestLoginDto dto)
        {
            return Send(await _loginServer.LoginByPhone(dto, "suppliers"));
        }
        /// <summary>
        /// 商家通过账号登录
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> BusinessLoginByAccount(RequestLoginDto dto)
        {
            return Send(await _loginServer.LoginByAccount(dto, "business"));
        }
        /// <summary>
        /// 商家通过手机号登录
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> BusinessLoginByPhone(RequestLoginDto dto)
        {
            return Send(await _loginServer.LoginByPhone(dto, "business"));
        }
        /// <summary>
        /// 检查管理端登录
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [CheckLogin(new CheckLoginRoles[] {CheckLoginRoles.administrators})]
        public IActionResult CheckAdministratorLogin()
        {
            return Send(ResponseApiDto.Ok("已登录", _administrator.ToResponseDto(_account)));
        }

        /// <summary>
        /// 检查供应商端登录
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [CheckLogin(new CheckLoginRoles[] {CheckLoginRoles.suppliers})]
        public IActionResult CheckSupplierLogin()
        {
            return Send(ResponseApiDto.Ok("已登录", _supplier.ToResponseDto(_account)));
        }

        /// <summary>
        /// 检查商家端登录
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [CheckLogin(new CheckLoginRoles[] {CheckLoginRoles.business})]
        public IActionResult CheckBusinessLogin()
        {
            return Send(ResponseApiDto.Ok("已登录", _business.ToResponseDto(_account)));
        }
    }
}
